<template>
	<view class="mine-container" :style="{height: `${windowHeight}px`}">
		<!--顶部个人信息栏-->
		<view class="header-section">
			<view class="flex padding justify-between">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar xl round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round"
						mode="widthFix">
					</image>
					<view v-if="!name" @click="handleToLogin" class="login-tip">
						点击登录
					</view>
					<view v-if="name" @click="handleToInfo" class="user-info">
						<text>
							学号/工号：{{ name }}
						</text>
					</view>
				</view>
				<view @click="handleToInfo" class="flex align-center">
					<text>个人信息</text>
					<view class="iconfont icon-right"></view>
				</view>
			</view>
		</view>

		<!-- <view class="content-section">
      <view class="mine-actions grid col-4 text-center">
        <view class="action-item" @click="handleJiaoLiuQun">
          <view class="iconfont icon-friendfill text-pink icon"></view>
          <text class="text">交流群</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-service text-blue icon"></view>
          <text class="text">在线客服</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-community text-mauve icon"></view>
          <text class="text">反馈社区</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon-dianzan text-green icon"></view>
          <text class="text">点赞我们</text>
        </view>
      </view> -->

		<view class="content">
			<!-- <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view class="iconfont icon-user menu-icon"></view>
            <view>编辑资料</view>
          </view>
        </view> -->
			<!-- <view class="list-cell list-cell-arrow" @click="handleHelp">
			<view class="menu-item-box">
				<view class="iconfont icon-help menu-icon"></view>
				<view>教师信息</view>
				<view>协助人信息</view>
			</view>
		</view> -->
			<view v-for="(item,index) in tableData" :key="index">
				<!-- <view class="list-cell list-cell-arrow" @click="handleHelp">
					<view class="menu-item-box">
						<view class="iconfont icon-help menu-icon"></view>
						<view>教师信息</view>
						<view>{{item.instrumentName}}</view>
						<br>
						<view v-if="assist[index]==0">未设置协助人</view>
						<view v-if="assist[index]==1">已设置协助人</view>
					</view>
				</view> -->
				<uni-card :title="item.instrumentName" extra=">"
					@click="handleHelp(item.instrumentId,item.instrumentName)">
					<view class="interval">
						<text class="card-text-first">设备编号：{{item.instrumentId}}</text>
						<!-- <text class="card-text">存放位置：{{item.storageLocation}}</text> -->
					</view>
					<view class="interval">
						<text class="card-text">存放位置：{{item.storageLocation}}</text>
					</view>
					<!-- <view v-if="assist[index]==1">
						<view class="interval">
							<text class="card-text-first">工号/学号：{{aD[index].id}}</text>
							<text class="card-text">姓名：{{aD[index].name}}</text>
						</view>
						<view class="check-mark">
							<text class="msg-tag pass">已设置协助人</text>
							<uni-icons type="forward" size="10" class="ico"></uni-icons>
						</view>
					</view>
					<view v-else>
						<view class="check-mark">
							<text class="msg-tag wait">未设置协助人</text>
							<uni-icons type="forward" size="10" class="ico"></uni-icons>
						</view>
					</view> -->
					<view v-if="assistData[index].note2==1">
						<view class="interval">
							<text class="card-text-first">工号/学号：{{assistData[index].assistId}}</text>
							<text class="card-text">姓名：{{assistData[index].assistName}}</text>
						</view>
						<view class="check-mark">
							<text class="msg-tag pass">已设置协助人</text>
							<!-- <uni-icons type="forward" size="10" class="ico"></uni-icons> -->
						</view>
					</view>
					<view v-else>
						<view class="check-mark">
							<text class="msg-tag wait">未设置协助人</text>
							<!-- <uni-icons type="forward" size="10" class="ico"></uni-icons> -->
						</view>
					</view>

				</uni-card>
			</view>
			<view style="height: 40px;"></view>
			<!-- <view class="list-cell list-cell-arrow" @click="handleAbout">
          <view class="menu-item-box">
            <view class="iconfont icon-aixin menu-icon"></view>
            <view>关于我们</view>
          </view>
        </view> -->
			<!-- <view class="list-cell list-cell-arrow" @click="handleToSetting">
          <view class="menu-item-box">
            <view class="iconfont icon-setting menu-icon"></view>
            <view>应用设置</view>
          </view>
        </view> -->
		</view>

	</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage';
	import {
		listEquipment,
		listEquipments,
	} from '@/api/module/wtc/equipment.js'
	import {
		listAssist
	} from '@/api/module/wtc/assist.js'

	export default {
		data() {
			return {
				name: this.$store.state.user.name,
				version: getApp().globalData.config.appInfo.version,
				// 设备表查询参数
				queryParams: {
					// pageNum: 1,
					// pageSize: 10,
					instrumentId: null,
					instrumentName: null,
					equipmentType: null,
					applicationDepartment: null,
					modelNumber: null,
					specification: null,
					unitPrice: null,
					classifyNumber: null,
					purchaseDate: null,
					receiverId: null,
					receiverName: null,
					manufacturers: null,
					storageDate: null,
					storageLocation: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				tableData: [],
				assist: [],
				// 协助人表查询参数
				aQueryParams: {
					receiverId: null,
					receiverName: null,
					assistName: null,
					assistId: null,
					userId: null,
					deptId: null,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					remark: null,
					note1: null,
					note2: null,
					note3: null,
					note4: null,
					note5: null,
					note6: null,
					note7: null,
					note8: null,
					note9: null,
					note10: null
				},
				assistData: [],
				aD: [],
			}
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		created() {
			this.queryParams.receiverId = this.name
			this.getList()
		},
		methods: {
			getList() {
				listEquipment(this.queryParams).then(res => {
					this.tableData = res.rows
					// console.log(this.tableData)
					// for (let i = 0; i < this.tableData.length; i++) {
					// 	this.getAssist(this.tableData[i].instrumentId)
					// }
					// console.log(this.assist)
					// console.log(this.aD)
					listEquipments(this.queryParams).then(response => {
						this.assistData = response.rows
					})
				})
			},
			// getAssist(instrumentId) {
			// 	this.aQueryParams.note1 = instrumentId
			// 	listAssist(this.aQueryParams).then(response => {
			// 		console.log(response.rows)
			// 		if (response.rows.length != 0) {
			// 			this.assistData = response.rows
			// 			if (this.assistData[0].assistId != '') {
			// 				this.assist.push("1")
			// 				this.aD.push({
			// 					id: this.assistData[0].assistId,
			// 					name: this.assistData[0].assistName,
			// 				})
			// 			} else {
			// 				this.assist.push("0")
			// 				this.aD.push({
			// 					id: '',
			// 					name: '',
			// 				})
			// 			}
			// 		} else {
			// 			this.assist.push("0")
			// 			this.aD.push({
			// 				id: '',
			// 				name: '',
			// 			})
			// 		}
			// 	})
			// },
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleHelp(instrumentId, instrumentName) {
				const id = instrumentId
				const iname = instrumentName
				this.$tab.navigateTo('/pages/module/lyq/perfect?id=' + id + '&name=' + iname)
			},
			handleAbout() {
				this.$tab.navigateTo('/pages/mine/about/index')
			},
			handleJiaoLiuQun() {
				this.$modal.showToast('QQ群：133713780')
			},
			handleBuilding() {
				this.$modal.showToast('模块建设中~')
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f5f6f7;
	}

	.mine-container {
		width: 100%;
		height: 100%;


		.header-section {
			padding: 15px 15px 45px 15px;
			background-color: #3c96f3;
			color: white;

			.login-tip {
				font-size: 18px;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 2px solid #eaeaea;

				.icon {
					font-size: 40px;
				}
			}

			.user-info {
				margin-left: 15px;

				.u_title {
					font-size: 18px;
					line-height: 30px;
				}
			}
		}

		.content-section {
			position: relative;
			top: -50px;

			.mine-actions {
				margin: 15px 15px;
				padding: 20px 0px;
				border-radius: 8px;
				background-color: white;

				.action-item {
					.icon {
						font-size: 28px;
					}

					.text {
						display: block;
						font-size: 13px;
						margin: 8px 0px;
					}
				}
			}
		}

		.content {
			text-align: center;
			font-weight: bold;
			background-color: #f1f1f1;
		}

		.card-text {
			font-weight: normal;
			color: #000000;
		}

		.card-text-first {
			font-weight: normal;
			margin-right: 5%;
			color: #000000;
		}

		.interval {
			margin-bottom: 10px;
		}

		.check-mark {
			display: block;
			text-align: right;
		}

		.msg-tag {
			position: relative;
			color: #fff;
			text-transform: uppercase;
			padding: 3px 10px;
			font-size: 10px;
			border-radius: 50px;
		}

		.msg-tag.wait {
			background: #007aff;
			font-weight: normal;
			margin-left: 65%;
		}

		.msg-tag.pass {
			background: #18bc37;
			font-weight: normal;
			margin-left: 65%;
		}
	}
</style>
